import ajax, { ListResult } from '../ajax';

export function getList(data: any) {
  return ajax.post<ListResult>(`/ControlPanels/Groups/Query`, data);
}

export function updateEntity(data: any) {
  if (!data.application) {
    data.applicationId = 10;
  }

  if (data.groupId) {
    return ajax.put<any>('/ControlPanels/Groups', data);
  } else {
    return ajax.post<any>('/ControlPanels/Groups', data);
  }
}

export function deleteEntity(id: number) {
  let deleteCommand = { id: id };
  return ajax.put<any>('/ControlPanels/Groups/Actions/Delete', deleteCommand);
}

export function getGroupRoles(groupId: number) {
  return ajax.get<Array<any>>(`/ControlPanels/Groups/${groupId}/Roles`);
}

export function bindRole(groupId: number, roleId: number) {
  let data = {
    groupId,
    roleId,
  };
  return ajax.post(`/ControlPanels/Groups/Actions/Bind/Role`, data);
}

export function unbindRole(groupId: number, roleId: number) {
  let data = {
    groupId,
    roleId,
  };
  return ajax.post(`/ControlPanels/Groups/Actions/Unbind/Role`, data);
}
